import 'package:flutter/material.dart';

class CustomAvatarView extends StatelessWidget {
  final String name;
  final String? avatarUrl;
  final double textSize;
  final double size;

  CustomAvatarView({required this.name, this.avatarUrl, this.textSize = 16, this.size = 50});

  @override
  Widget build(BuildContext context) {
    String displayName = name.length > 2 ? name.substring(name.length - 2) : name;

    return Container(
      width: size,
      height: size,
      decoration: BoxDecoration(
        color: Colors.green,
        borderRadius: BorderRadius.circular(10.0),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          if (avatarUrl != null && avatarUrl!.isNotEmpty)
            CircleAvatar(
              radius: size * 0.3,
              backgroundImage: NetworkImage(avatarUrl!),
            ),
          if (avatarUrl == null || avatarUrl!.isEmpty)
            Text(
              displayName,
              style: TextStyle(color: Colors.white, fontSize: textSize),
              textAlign: TextAlign.center,
            ),
        ],
      ),
    );
  }
}
